import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-26
 * Time: 19:54
 */
public class Solution {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        //将元素放入set中
        for(int num : nums){
            set.add(num);
        }
        int maxCount = 0;
        //找到起点
        for(int num : set){
            if(!set.contains(num - 1)) {
                int curNum = num;
                //记录这个起点的连续数
                int curCount = 1;
                while (set.contains(curNum + 1)) {
                    curNum++;
                    curCount++;
                }
                //选择最大的连续数
                maxCount = Math.max(curCount, maxCount);
            }
        }
        return maxCount;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] array = new int[]{100,4,200,1,3,2};
        int ret = solution.longestConsecutive(array);
        System.out.println(ret);
    }
}
